package day12.exception;

import java.util.Scanner;

public class Bank {
    static double balance = 10000;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入取款金额：");
        double db = sc.nextDouble();
        Bank bk = new Bank();
        if (db<0){
            bk.withDrawal(db);
        }else {
            try {
                throw new NagativeException("取款失败！取款数额为负数！");
            }catch (NagativeException e){
                System.out.println(e.getMessage());
            }
        }

    }
    public void withDrawal(double dAmount) {
        if (dAmount > balance) {
            System.out.println("成功取出" + dAmount + "元");
            balance = balance - dAmount;
        } else {
            try {
                throw new BalanceException("取款的金额大于存款！");
            } catch (BalanceException e) {
                System.out.println(e.getMessage());
            }
        }

    }
}

class BalanceException extends Exception{
    public BalanceException(){

    }
    public BalanceException(String msg){
        super(msg);
    }
}

class NagativeException extends Exception{
    public NagativeException(){

    }
    public NagativeException(String msg){
        super(msg);
    }
}

